#*********************************************************#
#                                                         #
#                                                         #
#                 REPLICATION FILES FOR:                  #
#                                                         #
#                 Hansen and Tummers                      #
#                                                         #
#       A Systematic Review of Field Experiments in       #
#                 Public Administration                   #
#                                                         #
#             Public Administration Review                #
#                                                         #
#                                                         #         
#*********************************************************#

#***************#
# Load Packages #
#***************#

library(tidyverse)
library(ggplot2)

#***************#
#   Load Data   #
#***************#
experiments <- read_delim("C:/Users/jespe/Desktop/Projekter/Systematic review of field experiments/data/field experiments.csv", 
                            delim = ";", escape_double = FALSE)

###############
###FIGURE 2####
###############
experiments %>%
  group_by(Year) %>%
  summarize(count = n(),
            dens = count / 42) %>%
  ggplot(aes(Year, count)) + 
  geom_bar(color = "black", stat = "identity", alpha =.9)+
  theme(axis.text.y = element_blank())+
  labs(
    x = "Year", y = "", 
    title = "Figure 2. Field experimentation over time",
    family = "Times",
    size = 10)+  
  theme(plot.title=element_text(family="Times", face="bold", size=12))+
  theme(axis.text.x = element_text(family = "Times", size = 8))+
  theme(axis.title.x = element_blank())+
  geom_text(aes(label = c("2010: 2", "2011: 1", "2013: 7", "2014: 3", "2015: 5", "2016: 4", 
                          "2017: 5", "2018: 10", "2019: 5")), 
            color= "white", family = "serif", vjust = 1, fontface = "bold", size = 2.3)+
  geom_text(aes(label = c("5 %", "2 %", "17 %", "7 %", "12 %", "10 %", "12 %", "24 %", "12 %")), 
             vjust = c(2.3, 2, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3),
             fontface = "bold", family ="serif", color = "white", size =2.5)+
  theme_minimal()+
scale_x_continuous(breaks = NULL, limits = c(2009, 2020))+
scale_y_continuous(breaks = seq(0, 15, by = 2))+
  geom_text(x = 2010.5, y = 8, color = "black", alpha = .2, size = 3,
            label = "Increasing trend in\n field experimentation. \n There are no published \nfield experiments before \n2010")+
  theme(axis.text.x = element_blank(), axis.text.y = element_blank(),
        axis.title.x = element_blank(),
        panel.grid.major =element_line(color ="grey70", size=.2))+
  geom_text(x = 2009, y = -0.3, color = "black", label = "2009", size = 2.5)+
geom_text(x = 2012, y = -0.3, color = "black", label = "2012", size = 2.5)

###############
####TABLE 1####
###############
experiments %>%
  group_by(Topic) %>%
  summarize(count = n(),
            perc = count / 42) %>%
  arrange(desc(count))
